//package com.leon.workenginespace.utils;
//
//import io.netty.util.concurrent.DefaultThreadFactory;
//
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//import java.util.concurrent.ScheduledThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
///**
// * @description:分布式Reids锁工厂接口
// * @author: WT
// * @date: 2024/4/12 0:19
// * @Version 1.0
// **/
//public class DistributedLockFactory {
//    public static final int BATCH = 1000;
//    private static Map<String, DistributedLock> lockMap = new ConcurrentHashMap();
//    private static DistributedImplBuilder implBuilder;
//    public static final int PERIOD = 10;
//
//    public DistributedLockFactory() {
//    }
//
//    private static <T> void clearIfNeed(Map<String, T> target) {
//        if (target.size() > 1000) {
//            target.clear();
//        }
//
//    }
//
//    public static DistributedLock buildLock(String name) {
//        DistributedLock lock = (DistributedLock)lockMap.get(name);
//        if (lock == null) {
//            synchronized(lockMap) {
//                lock = (DistributedLock)lockMap.get(name);
//                if (lock == null && implBuilder != null) {
//                    lock = implBuilder.buildLock(name);
//                    lockMap.put(name, lock);
//                }
//            }
//        }
//
//        return lock;
//    }
//
//    public static DistributedLock buildFairLock(String name) {
//        DistributedLock lock = (DistributedLock)lockMap.get(name);
//        if (lock == null) {
//            synchronized(lockMap) {
//                lock = (DistributedLock)lockMap.get(name);
//                if (lock == null && implBuilder != null) {
//                    lock = implBuilder.buildFairLock(name);
//                    lockMap.put(name, lock);
//                }
//            }
//        }
//
//        return lock;
//    }
//
//    public static DistributedReadWriteLock buildReadWriteLock(String name) {
//        DistributedReadWriteLock readWriteLock = (DistributedReadWriteLock)readWriteLockMap.get(name);
//        if (readWriteLock == null) {
//            synchronized(readWriteLockMap) {
//                readWriteLock = (DistributedReadWriteLock)readWriteLockMap.get(name);
//                if (readWriteLock == null && implBuilder != null) {
//                    readWriteLock = implBuilder.buildReadWriteLock(name);
//                    readWriteLockMap.put(name, readWriteLock);
//                }
//            }
//        }
//
//        return readWriteLock;
//    }
//
//    public static DistributedSequence buildNormalSequence(String name) {
//        DistributedSequence sequence = (DistributedSequence)sequenceMap.get(name);
//        if (sequence == null) {
//            synchronized(sequenceMap) {
//                sequence = (DistributedSequence)sequenceMap.get(name);
//                if (sequence == null && implBuilder != null) {
//                    sequence = implBuilder.buildNormalSequence(name);
//                    sequenceMap.put(name, sequence);
//                }
//            }
//        }
//
//        return sequence;
//    }
//
//    public static DistributedSequence buildBatchSequence(String name) {
//        DistributedSequence sequence = (DistributedSequence)sequenceMap.get(name);
//        if (sequence == null) {
//            synchronized(sequenceMap) {
//                sequence = (DistributedSequence)sequenceMap.get(name);
//                if (sequence == null && implBuilder != null) {
//                    sequence = implBuilder.buildBatchSequence(name);
//                    sequenceMap.put(name, sequence);
//                }
//            }
//        }
//
//        return sequence;
//    }
//
//    public static Map<String, DistributedLock> getLockMap() {
//        return lockMap;
//    }
//
//    public static void setLockMap(Map<String, DistributedLock> lockMap) {
//        DistributedLockFactory.lockMap = lockMap;
//    }
//
//    public static Map<String, DistributedReadWriteLock> getReadWriteLockMap() {
//        return readWriteLockMap;
//    }
//
//    public static void setReadWriteLockMap(Map<String, DistributedReadWriteLock> readWriteLockMap) {
//        DistributedLockFactory.readWriteLockMap = readWriteLockMap;
//    }
//
//    public static Map<String, DistributedSequence> getSequenceMap() {
//        return sequenceMap;
//    }
//
//    public static void setSequenceMap(Map<String, DistributedSequence> sequenceMap) {
//        DistributedLockFactory.sequenceMap = sequenceMap;
//    }
//
//    public static DistributedImplBuilder getImplBuilder() {
//        return implBuilder;
//    }
//
//    public static void setImplBuilder(DistributedImplBuilder implBuilder) {
//        DistributedLockFactory.implBuilder = implBuilder;
//    }
//
//    static {
//        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new DefaultThreadFactory("lock-cleaner"));
//        executor.scheduleWithFixedDelay(() -> {
//            clearIfNeed(lockMap);
//            clearIfNeed(readWriteLockMap);
//            clearIfNeed(sequenceMap);
//        }, 10L, 10L, TimeUnit.SECONDS);
//    }
//}